package com.sunyard.inser.sys.service.impl;

import org.apache.dubbo.config.annotation.DubboService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sunyard.inser.common.dto.InserException;
import com.sunyard.inser.common.enums.ErrorCode;
import com.sunyard.inser.dto.DataTablesResult;
import com.sunyard.inser.dto.PageInfo;
import com.sunyard.inser.sys.entity.UserInfo;
import com.sunyard.inser.sys.mapper.UserInfoMapper;
import com.sunyard.inser.sys.service.UserService;

@DubboService
public class UserServiceImpl implements UserService{
	
	private final static Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);
	
	@Autowired
	private UserInfoMapper userInfoMapper;

	@Override
	public DataTablesResult getUserPage(PageInfo pageInfo, UserInfo userInfo) {
		
		DataTablesResult result = new DataTablesResult();
		
		try {
			PageHelper.startPage(pageInfo.getPageNum(), pageInfo.getPageSize());
			Page<UserInfo> userInfoList = userInfoMapper.findList(userInfo);
			
			int total = userInfoMapper.count(userInfo).intValue();
			
			result.setData(userInfoList);
			result.setRecordsTotal(total);
			result.setCode(ErrorCode.SUCCESS.getCode());
			
		}catch (InserException e) {
			logger.error("", e);
			result.setCode(ErrorCode.ERROR.getCode());
			result.setMessage(e.getMessage());
		}
		
		
		
		return result;
	}

}
